Repository navigation
agentHost: turn on client forwarding with a CLI flag and from editor windows - #350856
Christof Marti (chrmarti) wants to merge 2 commits into
Conversation
The Dev Container launcher turned on client forwarding by prefixing the spawn command with VSCODE_AGENT_HOST_CLIENT_FORWARDING=1. That was implicit, and since the launcher reuses a running Agent Host of the same quality, it could pick one started without forwarding, for example by a remote editor's server. `code agent host --client-forwarding` now records `clientForwarding` in the Agent Host's endpoint registry entry and sets the variable for its server only with the flag, removing it otherwise. The launcher passes the flag and reuses only Agent Hosts started with it. The client's own CLI, the latest CLI of dev builds and fallback CLIs from 1.149 on have the flag; with an older fallback CLI, the Agent Host does not forward. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Registration polling can select a non-forwarding endpoint, and failed CLI refreshes can incorrectly enable an unsupported forwarding flag, causing missing credential forwarding or registration timeouts.
2 open issues
What changed in this PR
Makes Dev Container client forwarding an explicit CLI opt-in, following #350751. The endpoint registry now identifies forwarding-enabled Agent Hosts so the launcher can select compatible instances.
Changes:
- Adds hidden
--client-forwardingsupport, argument conflict checks, and explicit control of the server’s forwarding environment variable. - Records forwarding status and uses it for Dev Container host reuse, with compatibility handling for older fallback CLIs.
- Updates Rust and TypeScript tests and documents the launch behavior.
| File | Description |
|---|---|
src/vs/workbench/contrib/sessions/providers/remoteAgentHost/REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md |
Documents forwarding-aware launches and older CLI behavior. |
src/vs/platform/agentHost/test/node/sshRemoteAgentHostHelpers.test.ts |
Tests spawn options and CLI version detection. |
src/vs/platform/agentHost/test/node/devContainerAgentHostService.test.ts |
Tests forwarding-aware host selection and fallback CLIs. |
src/vs/platform/agentHost/test/node/agentHostEndpointRegistry.test.ts |
Tests forwarding metadata parsing. |
src/vs/platform/agentHost/node/sshRemoteAgentHostHelpers.ts |
Adds the spawn flag and version-support helper. |
src/vs/platform/agentHost/node/serviceBootstrapping.md |
Documents CLI-controlled forwarding startup. |
src/vs/platform/agentHost/node/remoteAgentHostCliInstaller.ts |
Returns fallback CLI version information. |
src/vs/platform/agentHost/node/devContainerAgentHostService.ts |
Requests forwarding and filters reusable endpoints. |
src/vs/platform/agentHost/node/agentHostClientForwarding.ts |
Updates the environment-variable documentation comment. |
src/vs/platform/agentHost/LOCAL_ENDPOINT.md |
Documents the optional registry field. |
src/vs/platform/agentHost/common/agentHostEndpointRegistry.ts |
Validates and preserves forwarding metadata. |
cli/src/tunnels/agent_host.rs |
Controls the server environment and publishes forwarding status. |
cli/src/tunnels/agent_host_registry.rs |
Serializes forwarding status and carries it through selection. |
cli/src/commands/args.rs |
Defines the hidden flag and incompatible modes. |
cli/src/commands/agent_relay.rs |
Updates a registry test fixture. |
cli/src/commands/agent_host.rs |
Propagates the flag and rejects incompatible supervisor reuse. |
Review effort: Balanced
The Dev Container launcher again reuses the Agent Host running in the container however it was started, so the endpoint registry no longer records client forwarding. Instead, an editor window connected to a Dev Container asks its server, with the new `clientForwarding` connection option, to start its Agent Host with forwarding, since the launcher may reuse that one. The launcher now stops waiting for a new Agent Host to register as soon as its start command fails, and starts it again without `--client-forwarding` when a 1.149 CLI from before the flag rejects it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Credential, SSH-agent, and GPG forwarding across shared hosts lacks real Dev Container end-to-end validation, requiring maintainer checks of launcher-first startup, editor-first reuse, and crash restarts.
No open issues 🎉
2 resolved since last review
Review effort: Balanced

Follow-up to #350751. Replaces the environment variable that the Dev Container launcher used to turn on client forwarding with a
code agent host --client-forwardingflag, and lets editor windows connected to a Dev Container turn it on for the Agent Host their server starts, which the launcher may reuse.The launcher prefixed its spawn command with
VSCODE_AGENT_HOST_CLIENT_FORWARDING=1, which was implicit. And since the launcher reuses any running Agent Host of the same quality, it often picked the one a remote editor window's server had started in the container, which never forwarded.CLI (
cli/)--client-forwardingflag oncode agent host/code agent, not allowed with--tunnelor--github-environment.VSCODE_AGENT_HOST_CLIENT_FORWARDING=1for the server it starts only with the flag, and removes it otherwise, so an inherited variable can't turn forwarding on. The server passes it on to its Agent Host, which reads and removes it as before.Editor windows
dev-containerorattached-container) asks its server for forwarding with a newclientForwardingIPC connection option, next to the resolver environment it already passes.common/agentService.tsasAgentHostClientForwardingEnvVar, so the server can use it.Dev Container launcher
--client-forwardinginstead of the variable. The CLI of the client's commit and the latest CLI that dev builds use get the flag, as do fallback CLIs whose--versionis 1.149 or later (ordev); the CLI installer now also returns a fallback CLI's--versionoutput. An older fallback CLI starts the Agent Host without the flag, with a warning.unexpected argument '--client-forwarding'), as 1.149 builds from before it do, starts the Agent Host again without it.How to test
ps -ef | grep agentshowsagent host ... --client-forwarding, and Git credentials,ssh-add -land GPG signing work in a session's terminal.Validation:
pnpm run typecheck-client: passednode build/oxlint.ts <changed .ts files>: passedpnpm run precommit(hygiene on the staged files): passedpnpm run build-fast --client-only: passed.\scripts\test.bat --run src/vs/platform/agentHost/test/node/devContainerAgentHostService.test.ts --run src/vs/platform/agentHost/test/node/sshRemoteAgentHostHelpers.test.ts --run src/vs/platform/agentHost/test/node/remoteAgentHostCliInstaller.test.ts --run src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts --run src/vs/platform/agentHost/test/node/agentHostClientForwarding.test.ts --run src/vs/platform/agentHost/test/node/agentHostEndpointRegistry.test.ts --run src/vs/server/test/node/agentHostChannel.test.ts --run src/vs/server/test/node/serverAgentHostEnvironment.test.ts --run src/vs/workbench/services/agentHost/test/browser/editorRemoteAgentHostServiceClient.test.ts: passed (386 passing, 4 pending)rust:1container (Rust 1.100), on a copy ofcli/with the rootpackage.jsonandproduct.json:cargo test --locked: passed (235 passed)cargo fmt --check: no differences in changed lines; this rustfmt flags existing code elsewherecargo clippy --all-targets --locked -- -D warnings: two errors, both in existing tests this change doesn't touch (an unnecessarycloneto create a slice incommands/agent_host.rs, andclippy::async_yields_asyncintunnels/agent_host.rs), from lints in this newer clippy